package com.deprecated.patch;

import java.math.BigDecimal;

import com.panopset.compat.Strings;

public class ValidatingBigDecimal extends ValidatingField<BigDecimal> {

    /**
     * @param name
     *            Name of field, used in validation messages.
     */
    public ValidatingBigDecimal(final String name) {
        super(name);
    }

    @Override
    public BigDecimal getValue() {
        try {
            return new BigDecimal(getTf().getText());
        } catch (NumberFormatException ex) {
            return BigDecimal.ZERO;
        }
    }

    @Override
    public boolean validate(final String s) {
        if (!Strings.isPopulated(s)) {
            return false;
        }
        try {
            new BigDecimal(s);
            return true;
        } catch (NumberFormatException ex) {
            return false;
        }
    }

    @Override
    public void save() {
        // TODO Auto-generated method stub

    }

}
